import 'dart:convert';

BaseResp baseRespFromJson(String str) => BaseResp.fromJson(json.decode(str));

String baseRespToJson(BaseResp data) => json.encode(data.toJson());

class BaseResp<T> {
  BaseResp({
    required this.errorCode,
    required this.errorMsg,
    required this.data,
  });

  late int errorCode;
  late String errorMsg;
  late Map<String, dynamic> data;

  BaseResp.fromJson(Map<String, dynamic> json) {
    print('1111111111111111-------${json["data"]}');
    data = json['data'];
    errorCode = json["errorCode"];
    errorMsg = json["errorMsg"];
  }

  BaseResp dataConvert() {
    if (errorCode == 1) {
      return this;
    }
    errorMsg = "错误";
    throw ApiException(errorCode, errorMsg);
  }

  Map<String, dynamic> toJson() => {
        "errorCode": errorCode,
        "errorMsg": errorMsg,
        "data": data,
      };
}

class ApiException implements Exception {
  int errorCode;
  String errorMsg;

  ApiException(this.errorCode, this.errorMsg);
}
